<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.Locale"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.HashSet"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Set"%>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
    <%
    Locale l = request.getLocale();
    UserService userService = UserServiceFactory.getUserService();
    %>

    <c:choose> 
        <c:when test="${!(empty param.locale)}"> 
            <c:set var="loc" value="${param.locale}"/>
        </c:when> 
        <c:otherwise> 
            <c:set var="loc" value="<%=l%>"/>
        </c:otherwise> 
    </c:choose> 

    <fmt:setLocale value="${loc}" />
    <fmt:bundle basename="messages">
        <head>
            <title><fmt:message key="appTitle"/> <fmt:message key="uploadImage"/></title>
            <link rel="stylesheet" href="./css/index.css" type="text/css" />
            <script type="text/javascript" src="./js/jquery-1.5.1.min.js"></script>
            <script language="javascript">
            function doLogin()
            {
            	document.location.href="<%=userService.createLoginURL(request.getRequestURI())%>";
            }
  
            function uploadComment()
            {
            	$("#uploadStatus").text("uploading comment to place....");
            	$.post("/rpc", {
            		action : "addPlaceComment",
            		arg0 :  $("#arg0").val(),
            		arg1 :  $("#arg1").val(),
            		arg2 :  $("#arg2").val(),
            		arg3 :  $("#arg3").val()
            	}, onUploadCommentSuccess);            	
            }
            
            function onUploadCommentSuccess(response)
            {
            	if (response == null) {
            		$("#uploadStatus").text("No se ha obtenido respuesta");
            		return;
            	}
            	else
            	{
            		$("#uploadStatus").text(JSON.stringify(response));               		           		
            	}
            }
            
            </script>
        </head>
        <body>
            <h1><fmt:message key="appTitle"/></h1>
            <h2>Comment a Place</h2>

            <%
                if (userService.isUserLoggedIn()) {
                    User user = userService.getCurrentUser();
            %>
            <p>Hello, <%= user.getNickname() %>! (You can
                <a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>

                IdPlace: <input type="text" id="arg0" value="60002" /><br/>                               
                User: <input type="text" id="arg1" value="<%=user.getNickname()%>" /><br/>
                Comment:<br/><textarea type="text" id="arg2" style="width:300px;height:100px"></textarea><br/>
                Comment Type:
                <select id="arg3">
                <option value="1">PLACE</option>
                <option value="2">GENERAL</option>
                </select><br/> 
                <button id="uploadComment" onclick="uploadComment()">Upload Comment to Place</button><br/>
                <div id="uploadStatus"></div>
            <%
                } else {
            %>
            <button name="submit_button" id="submit_button" style="padding:5px;margin-top:20px;" onclick="doLogin()">
            <img src="http://www.google.com/favicon.ico" alt="Sign in with a Google Account" style="margin-bottom:-3px;">&nbsp; Sign in using your Google Account
          </button>
            </p>
            <%
                }
            %>
        </body>
    </fmt:bundle>
</html>










